<?php

namespace App\Http\Middleware;

use Closure;
use App\Http\Controllers\ClientController;
use Illuminate\Support\Facades\Log;

class ClientVerify extends ClientController
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        try{
            $we_id = decrypt($request->header('We-Token'));
            if(!is_int($we_id)){
                return $this->setReturnJson(-1,'您当前未登录');
            }
        }catch (\Exception $e){
//            Log::error(ClientVerify::class,['msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]);
            return $this->setReturnJson(-1,'登录状态异常，请点击左上角关闭当前页面，并重新进入');
        }
        return $next($request);
    }
}
